package com.oa.commons.ov;


import java.util.ArrayList;
import java.util.List;


//Page是VO对象，即Value Object对象，完成Java类与JSP页面的数据传递，加泛型是提高通用性
public class Page<T> {
    private int pageNum;//当前页的页码
    private int pageSize;//页面大小，每页可以显示的几条记录
    private int totalRows;//总条目数
    private int totalPages;//总页数
    private int pageStartIndex;//当前页记录的起始索引
    private List<T> datas;//当前页所包含的具体数据

    public Page() {
        pageNum = 1;
        pageSize = 3;
        datas =new ArrayList();
    }

    public Page(int pageNum, int pageSize) {
        if(pageNum <= 0){
            pageNum =1;
        }else{
            this.pageNum = pageNum;
        }
        if(pageSize <= 0){
            pageSize = 3;
        }else {
            this.pageSize = pageSize;
        }
    }

    public int getPageNum() {

        return pageNum;
    }

    public void setPageNum(int pageNum) {

        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getTotalPages() {

        if(totalRows % pageSize == 0){
            totalPages = totalRows/pageSize;
        }else {
            totalPages = totalRows/pageSize + 1;
        }
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getPageStartIndex() {
        pageStartIndex = (pageNum - 1) * pageSize;
        return pageStartIndex;
    }

    public void setPageStartIndex(int pageStartIndex) {
        this.pageStartIndex = pageStartIndex;
    }

    public List<T> getDatas() {

        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }
}

